<?php

namespace app\controller\index\ai;

use app\common\lib\Common;
use app\controller\index\BaseController;
use app\exception\IndexException;
use support\Request;
use support\Response;

class IndexController extends BaseController
{
    /**
     * @throws IndexException
     */
    public function generate(Request $request): Response
    {
        $content =$request->input("content", "");
        $cmd =$request->input("cmd", "");
        if (!$content) {
            throw new IndexException(4020, "内容不能为空");
        }
        if (!$cmd) {
            throw new IndexException(4020, "指令不能为空");
        }

        switch ($cmd) {
            case "overseas_parts_command": //内容分段
                $command = getAiCommand('overseas_parts_command');
                $data = Common::aiContentPartsToUser($content, $command);
                break;
            case "overseas_summary_command"://海外推广总结
                $command = getAiCommand($cmd);
                $data = Common::generatedContent($content, $command);
                break;
            default:
                throw new IndexException(4020, "指令错误");
        }

        return $this->endSuccess($data);
    }
}